<template>
  <div class="detail-nav-bar">
    <nav-bar>
      <div slot="left" class="back" @click="backClick">
        <img src="~@img/common/back.svg" />
      </div>

      <div slot="center" class="title">
        <div
          :key="index"
          :class="{ active: index === currentIndex }"
          @click="itemClick(index)"
          class="title-item"
          v-for="(item, index) in titles"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
  import NavBar from '@commoncpn/navbar/NavBar'

  export default {
    name: 'detail-nav-bar',
    components: { NavBar },
    data() {
      return {
        titles: ['商品', '参数', '评论', '推荐'],
        currentIndex: 0
      }
    },
    methods: {
      itemClick(index) {
        this.currentIndex = index
        this.$emit('navclick', index)
      },
      backClick() {
        this.$router.back()
      }
    }
  }
</script>

<style lang="less" scoped>
  .title {
    display: flex;
    font-size: 12px;
    .title-item {
      flex: 1;
    }
  }
  .back {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
  }
  .active {
    color: var(--color-tint);
  }
</style>
